package com.appwoo.txtws.service;

import android.annotation.SuppressLint;
import android.app.Service;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;
import android.content.res.Resources;
import android.os.AsyncTask;
import android.os.Handler;
import android.os.IBinder;
import android.os.Message;
import android.text.format.Time;
import com.appwoo.txtws.bean.WeatherBean;
import com.appwoo.txtws.component.CityHelper;
import com.appwoo.txtws.component.Global;
import com.appwoo.txtws.component.WeatherHelper;
import com.appwoo.txtws.thread.LocationTaskComplete;
import java.io.PrintStream;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

public class WeatherService extends Service
{
  public static final int MESSAGE_SAMPLE = 1;
  public static final int MESSAGE_WEATHER = 2;
  public static final String SP_KEY_WEATHER_CITYNAME = "cityname";
  public static final String SP_KEY_WEATHER_DATE = "lastUpdateDate";
  public static final String SP_KEY_WEATHER_IMG = "img";
  public static final String SP_KEY_WEATHER_STATUS = "weatherStatus";
  public static final String SP_KEY_WEATHER_TEMHIGH = "temHigh";
  public static final String SP_KEY_WEATHER_TEMLOW = "temLow";
  public static final String SP_NAME_WEATHER = "weather";
  private static Time TIME_WIDGET = new Time();
  public static boolean isOnCreate;
  public static String strHore = "";
  public static String strMin = "";
  private static WeatherBean weatherBean;
  String filename = "weather.gif";
  boolean flag = true;
  boolean is_run = false;
  private WidgetLocation localtion = new WidgetLocation(new LocationTaskComplete()
  {
    public void complete(String paramAnonymousString)
    {
      WeatherService.this.locationComplete = true;
      String str;
      if ((paramAnonymousString != null) && (!"".equals(paramAnonymousString)))
      {
        WeatherService.weatherBean = new WeatherBean();
        str = paramAnonymousString.replace("市", "");
        WeatherService.weatherBean = WeatherHelper.getCurrentWeather(CityHelper.getCityCodyByCityname(str));
        WeatherService.weatherBean.setCityName(str);
        if (WeatherService.weatherBean != null)
          WeatherService.weatherBean.getImg();
      }
      try
      {
        WeatherService.weatherBean.setCityName(str);
        return;
      }
      catch (Exception localException)
      {
        localException.printStackTrace();
      }
    }
  });
  boolean locationComplete = false;
  Handler sHandler;
  Thread sThread;

  @SuppressLint({"SimpleDateFormat"})
  private SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-DD HH:mm");
  Handler weatherHandler;
  Thread weatherThread;

  static
  {
    isOnCreate = false;
  }

  public static String getData(Resources paramResources)
  {
    Calendar localCalendar = Calendar.getInstance();
    int i = localCalendar.get(7);
    String str1 = null;
    switch (i)
    {
    default:
    case 1:
    case 2:
    case 3:
    case 4:
    case 5:
    case 6:
    case 7:
    }
    while (true)
    {
      int j = 1 + localCalendar.get(2);
      String str2 = String.valueOf(j);
      if (j < 10)
        str2 = "0" + str2;
      String str3 = String.valueOf(localCalendar.get(5));
      return str1 + ", " + str2 + "/" + str3;
      str1 = paramResources.getString(2131427851);
      continue;
      str1 = paramResources.getString(2131427852);
      continue;
      str1 = paramResources.getString(2131427853);
      continue;
      str1 = paramResources.getString(2131427854);
      continue;
      str1 = paramResources.getString(2131427855);
      continue;
      str1 = paramResources.getString(2131427856);
      continue;
      str1 = paramResources.getString(2131427857);
    }
  }

  public static void getTime()
  {
    TIME_WIDGET.setToNow();
    String str1;
    if (TIME_WIDGET.hour < 10)
    {
      str1 = "0" + TIME_WIDGET.hour;
      strHore = str1;
      if (TIME_WIDGET.minute >= 10)
        break label104;
    }
    label104: for (String str2 = "0" + TIME_WIDGET.minute; ; str2 = TIME_WIDGET.minute)
    {
      strMin = str2;
      return;
      str1 = TIME_WIDGET.hour;
      break;
    }
  }

  public static WeatherBean getWeatherBean()
  {
    return weatherBean;
  }

  private void startThread()
  {
    this.localtion.initLocation(this);
    isOnCreate = true;
    getData(getResources());
    Intent localIntent = new Intent();
    localIntent.setAction("refreshDate");
    sendBroadcast(localIntent);
    if (!this.is_run)
    {
      this.sThread = new Thread()
      {
        public void run()
        {
          try
          {
            while (true)
            {
              Thread.sleep(3000L);
              WeatherService.getTime();
              Message localMessage = new Message();
              localMessage.what = 1;
              WeatherService.this.sHandler.sendMessage(localMessage);
            }
          }
          catch (InterruptedException localInterruptedException)
          {
            while (true)
              localInterruptedException.printStackTrace();
          }
        }
      };
      this.sThread.start();
      this.sHandler = new Handler()
      {
        public void handleMessage(Message paramAnonymousMessage)
        {
          int i = paramAnonymousMessage.what;
          if (i == 1)
          {
            localIntent1 = new Intent();
            localIntent1.setAction("refreshTime");
            WeatherService.this.sendBroadcast(localIntent1);
            if (("00".equals(WeatherService.strMin)) || ("01".equals(WeatherService.strMin)))
            {
              localIntent2 = new Intent();
              localIntent2.setAction("refreshDate");
              WeatherService.this.sendBroadcast(localIntent2);
            }
          }
          while (2 != i)
          {
            Intent localIntent1;
            Intent localIntent2;
            return;
          }
          new WeatherService.LoadWeather(WeatherService.this).execute(new String[0]);
        }
      };
      this.weatherThread = new Thread()
      {
        public void run()
        {
          while (true)
            try
            {
              Thread.sleep(600000L);
              if (Global.updateWeather)
                Thread.sleep(1200000L);
              Message localMessage = new Message();
              localMessage.what = 2;
              WeatherService.this.sHandler.sendMessage(localMessage);
            }
            catch (InterruptedException localInterruptedException)
            {
              localInterruptedException.printStackTrace();
            }
        }
      };
      this.weatherThread.start();
      new LoadWeather().execute(new String[0]);
    }
  }

  public IBinder onBind(Intent paramIntent)
  {
    return null;
  }

  public void onCreate()
  {
    super.onCreate();
    startThread();
  }

  public void onDestroy()
  {
    System.out.println("onDestory");
    this.flag = false;
    super.onDestroy();
  }

  public void onStart(Intent paramIntent, int paramInt)
  {
    super.onStart(paramIntent, paramInt);
    if (isOnCreate)
    {
      isOnCreate = false;
      return;
    }
    this.is_run = true;
    getData(getResources());
    Intent localIntent1 = new Intent();
    localIntent1.setAction("refreshDate");
    sendBroadcast(localIntent1);
    Intent localIntent2 = new Intent();
    localIntent2.setAction("refreshWeather");
    sendBroadcast(localIntent2);
  }

  class LoadWeather extends AsyncTask<String, Integer, String>
  {
    LoadWeather()
    {
    }

    protected String doInBackground(String[] paramArrayOfString)
    {
      WeatherService.this.localtion.startLocation();
      while (true)
      {
        if (WeatherService.this.locationComplete)
          return null;
        try
        {
          Thread.sleep(3000L);
        }
        catch (InterruptedException localInterruptedException)
        {
          localInterruptedException.printStackTrace();
        }
      }
    }

    protected void onPostExecute(String paramString)
    {
      super.onPostExecute(paramString);
      SharedPreferences localSharedPreferences = WeatherService.this.getSharedPreferences("weather", 0);
      if ((WeatherService.weatherBean != null) && (WeatherService.weatherBean.getCityName() != null) && (!"".equals(WeatherService.weatherBean.getCityName())))
      {
        WeatherService.weatherBean.setImg(WeatherService.this.filename);
        SharedPreferences.Editor localEditor = localSharedPreferences.edit();
        localEditor.putString("lastUpdateDate", WeatherService.this.simpleDateFormat.format(new Date()));
        localEditor.putString("weatherStatus", WeatherService.weatherBean.getWeather());
        localEditor.putString("cityname", WeatherService.weatherBean.getCityName());
        localEditor.putString("temHigh", WeatherService.weatherBean.getTemHight());
        localEditor.putString("temLow", WeatherService.weatherBean.getTemLow());
        localEditor.putString("img", WeatherService.weatherBean.getImg());
        localEditor.commit();
        Global.updateWeather = true;
      }
      Intent localIntent = new Intent();
      localIntent.setAction("refreshWeather");
      WeatherService.this.sendBroadcast(localIntent);
    }

    protected void onPreExecute()
    {
      super.onPreExecute();
      Global.updateWeather = false;
    }
  }
}

/* Location:           C:\Documents and Settings\Administrator\classes_dex2jar.jar
 * Qualified Name:     com.appwoo.txtws.service.WeatherService
 * JD-Core Version:    0.6.2
 */